// 供方加扣款结算 详情
<template>
  <!-- 集采汇总编辑页 -->
  <div class="e-form">
    <!-- //详情 添加页面 ↓ -->
    <div class="tabs">
      <el-tabs tab-position="left" v-model="tabsName" @tab-click="onChangeTab">
        <!-- 基本信息 -->
        <el-tab-pane
          label="基本信息"
          name="baseInfo"
          :disabled="clickTabFlag"
        ></el-tab-pane>
        <el-tab-pane
          label="加扣款明细"
          name="planDetail"
          :disabled="clickTabFlag"
        ></el-tab-pane>

        <el-tab-pane
          label="返还保证金"
          name="fhbzj"
          :disabled="clickTabFlag"
        ></el-tab-pane>

        <el-tab-pane
          label="附件信息"
          name="accessory"
          :disabled="clickTabFlag"
        ></el-tab-pane>
        <el-tab-pane
          label="审核历史"
          name="auditHistory"
          :disabled="clickTabFlag"
        ></el-tab-pane>

        <!-- <el-tab-pane
          label="审核历史"
          name="auditHistory"
          :disabled="clickTabFlag"
        ></el-tab-pane> -->
        <div>
          <!-- 基本信息 -->
          <div id="baseInfoCon" class="con">
            <div class="e-form">
              <div class="tabs">
                <div class="tabs-title" id="baseInfo">基本信息</div>
                <div style="width: 100%" class="form">
                     <el-form ref="form" :model="form" label-width="150px">
                                    <el-row>
                                        <el-col :span="12" v-if="was != 'add'">
                                            <el-form-item label="结算编号：">
                                                <!-- <el-input v-model="formData.billNo"></el-input> -->
                                                <span>{{formData.billNo}}</span>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="单据机构：">
                                                <!-- <el-input v-model="formData.settlementUnitName"></el-input> -->
                                                <span>{{formData.orgName}}</span>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="合同类型：">
                                                <span>{{['物资采购','周材租凭','加工','设备采购','设备租凭','服务采购'][formData.contractType - 1]}}</span>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="合同名称：">
                                                 <span>{{formData.contractName}}</span>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="结算单位：">
                                                <el-input v-model="formData.settlementUnitName" :disabled="true"></el-input>
                                                <el-button size="small"
                            style="background: rgb(75, 178, 255); color: #fff" @click="truejcht">选择机材合同</el-button>
                                                <!-- <span>{{formData.settlementUnitName}}</span> -->
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="加扣款日期：">
                                                 <el-date-picker v-model="formData.settlementDate" type="date" placeholder="选择日期" :clearable="false">
                                                </el-date-picker>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="加扣款金额(元)：">
                                                <!-- <el-input v-model="formData.plusDeductionAmount"></el-input> -->
                                                <!-- <span>{{formData.plusDeductionAmount}}</span> -->
                                                <span>{{jkkje}}</span>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <!-- 返回id、名字 -->
                                            <el-form-item label="返还保证金金额(元)：">
                                                <!-- <el-input v-model="formData.rmbReturnDepositAmount"></el-input> -->
                                                <span>{{bzjje}}</span>
                                                <!-- <span>{{formData.rmbReturnDepositAmount}}</span> -->
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="币种：">
                                                <span>{{formData.currency}}</span>
                                                <!-- <el-input v-model="formData.currency"></el-input> -->
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="传财务共享：">
                                                <span>{{ formData.gx}}</span>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>

                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="本位币：">
                                                <span>{{formData.baseCurName}}</span>
                                               <!-- <el-input v-model="formData.baseCurName"></el-input> -->
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="状态：">
                                                <el-select :disabled="true" v-model="formData.state" placeholder="请选择">
                                                    <el-option
                                                        v-for="(item, index) in typeArr || []"
                                                        :key="index"
                                                        :label="item.name"
                                                        :value="item.id"
                                                    >
                                                    </el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>

                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="本位币汇率：">
                                               <!-- <el-input v-model="formData.baseCurRate"></el-input> -->
                                               <span>{{formData.baseCurRate}}</span>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>

                                      <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="加扣款金额(本位币)：">
                                                <span>{{jkkjeBwb}}</span>
                                               <!-- <el-input v-model="formData.baseCurPlusDeductionAmount"></el-input> -->
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="返还保证金金额(本位币)：">
                                                <span>{{bzjjeBwb}}</span>
                                                  <!-- <el-input v-model="formData.baseCurReturnDepositAmount"></el-input> -->
                                            </el-form-item>
                                        </el-col>
                                    </el-row>

                                      <el-row>
                                        <el-col :span="24">
                                            <el-form-item label="备注">
                                               <el-input type="textarea" :rows="2" laceholder="请输入内容" v-model="formData.remarks"></el-input>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>

                                </el-form>
                </div>
              </div>
            </div>
          </div>

          <!-- 加扣款明细 -->
          <div id="planDetailCon" class="con">
            <div class="tabs-title" id="planDetail">加扣款明细</div>
            <el-tabs
              :class="'childTab ' + childTabClass"
              tab-position="left"
              v-model="tabsNameChild"
              @tab-click="onChangeTab"
            >
              <el-tab-pane
                label="加扣款"
                name="materialDetails"
                :disabled="clickTabFlag"
              ></el-tab-pane>
              <el-tab-pane
                label="物资明细"
                name="technicalParameter"
                :disabled="clickTabFlag"
              ></el-tab-pane>
              <div>
                <div id="planDetailCon">
                  <div class="tabs-title" id="materialDetails">
                    加扣款
                  </div>
                  <div class="e-table">
                    <div class="top">
                      <div class="left">
                        <div>
                          <el-button
                            size="small"
                            style="background: rgb(75, 178, 255); color: #fff"
                            @click="addjkk"
                            >新增</el-button
                          >
                          <el-button
                            size="small"
                            type="danger"
                            @click="deljkk"
                            >删除</el-button
                          >
                        </div>
                      </div>
                    </div>

                    <el-table
                      :data="jkktableData"
                      border
                      style="width: 100%"
                      :row-class-name="tableRowClassName"
                        @cell-click="tableDbShow"

                      :cell-class-name="cellClsNm"
                      :header-cell-style="{ textAlign: 'center' }"
                      :cell-style="{ textAlign: 'center' }"
                      @selection-change="planTableSelect"
                    >
                      <el-table-column type="selection" width="55">
                      </el-table-column>
                      <el-table-column
                        label="加扣款名称"
                        min-width="200"
                      >
                        <template slot-scope="{ row }">
                            {{ row.name}}
                        </template>
                      </el-table-column>
                      <el-table-column
                        label="加扣款类别"
                        min-width="100"
                      >
                         <template slot-scope="{ row }">
                            {{ row.type - 0 == 1 ? '加款' : '扣款' }}
                        </template>
                      </el-table-column>
                      <el-table-column
                        label="规格"
                        min-width="300"
                      >
                         <template slot-scope="{ row }">
                              <el-input  v-model="row.spec"/>
                            <!-- {{ row.spec}} -->
                        </template>
                      </el-table-column>
                      <el-table-column
                        label="单位"
                        min-width="300"
                      >
                        <template slot-scope="{ row }">
                            <el-select v-model="row.unit" placeholder="请选择单位">
                                <el-option
                                    v-for="(item, index) in danweiArr || []"
                                    :key="index"
                                    :label="item.kvKey"
                                    :value="item.kvKey"
                                    >
                                </el-option>
                            </el-select>
                        </template>
                      </el-table-column>
                      <el-table-column
                        label="加扣款金额"
                        min-width="300"
                      >
                        <template slot-scope="{ row }">
                            <el-input type="number" v-model="row.amount"/>
                        </template>
                      </el-table-column>
                    </el-table>

                  </div>
                </div>

                <div id="planDetailCon">
                  <div class="tabs-title" id="technicalParameter">物资汇总</div>
                  <div class="e-table">
                    <div class="top">
                      <div class="left">
                        <div>
                          <el-button
                            size="small"
                            style="background: rgb(75, 178, 255); color: #fff"
                            @click="addhtqd"
                            >选择合同清单</el-button
                          >
                          <el-button
                            size="small"
                            type="danger"
                            >删除</el-button
                          >
                        </div>
                      </div>
                    </div>
                     <!-- :row-class-name="tableRowClassNames"
                          @cell-mouse-enter="cellMouseEnter"
                           @cell-click="cellClick"
                          @cell-mouse-leave="cellMouseLeave" -->
                    <el-table

                      :data="wzmxtable"
                      border
                        style="width: 100%; margin-top: 20px"
                          :cell-class-name="cellClsNm"
                          :header-cell-style="{ textAlign: 'center' }"
                          :cell-style="{ textAlign: 'center' }"
                          @selection-change="planTableSelect"
                          :tree-props="{
                              children: 'children',
                              hasChildren: 'hasChildren',
                            }"
                          row-key="uuid"
                    >
                      <el-table-column prop="topClassName" label="物资类别" width="150">
                      </el-table-column>
                      <el-table-column
                        prop="materialName"
                        label="物资名称"
                        min-width="200"
                      >
                      </el-table-column>
                      <el-table-column prop="spec" label="规格" width="100">
                      </el-table-column>
                      <el-table-column prop="texture" label="材质" width="100">
                      </el-table-column>
                      <el-table-column prop="unit" label="单位" width="100">
                      </el-table-column>
                      <el-table-column label="金额" width="100">
                          <template slot-scope="{ row }">
                            <!-- {{ row.name}} -->
                            <el-input v-if="row.billId || row.billId == ''" type="number" v-model="row.amount"  @keyup.native="changnum('金额',row)"></el-input>
                          </template>
                      </el-table-column>
                      <el-table-column  label="分摊比例" width="100">
                          <template slot-scope="{ row }">
                            <!-- {{ row.name}} -->
                            <el-input v-if="row.billId || row.billId == ''"  type="number" v-model="row.apportionmentRatio" @keyup.native="changnum('比例',row)" ></el-input>
                          </template>
                      </el-table-column>
                    </el-table>
                  </div>
                </div>
              </div>
            </el-tabs>
          </div>

          <!-- 返还保证金 -->
          <div id="fhbzjCon" class="con">
            <div class="tabs-title" id="fhbzj">返还保证金</div>
            <div class="e-table" style="min-height: auto">
                <div class="top">
                      <div class="left">
                        <div>
                          <el-button
                            size="small"
                            style="background: rgb(75, 178, 255); color: #fff"
                            @click="xzbzj"
                            >选择保证金</el-button
                          >
                          <el-button
                            size="small"
                            type="danger"
                            >删除</el-button
                          >
                        </div>
                      </div>
                    </div>
                              <!-- @cell-mouse-enter="cellMouseEnter"
                                @cell-mouse-leave="cellMouseLeave"
                                :cell-class-name="cellClsNm" -->
                            <el-table
                                :data="bzjtableData"
                                border
                                style="width: 100%"
                            >
                                <el-table-column prop="name" label="保证金名称" > </el-table-column>
                                <el-table-column prop="withholdAmount" label="暂扣保证金(元)" width="250"> </el-table-column>
                                <el-table-column prop="notReturnedAmount" label="截止上期末未返还保证金(元)" width="250"> </el-table-column>
                                 <el-table-column label="返还保证金(元)" width="200">
                                      <template slot-scope="{ row }">
                                        <el-input type="number" v-model="row.returnAmount"/>
                                        </template>
                                </el-table-column>
                                <el-table-column label="截止本期末未返还保证金(元)" width="200">
                                     <template slot-scope="{ row }">
                                         <span>{{row.notReturnedAmount - row.returnAmount}}</span>
                                        </template>
                                </el-table-column>
                                <el-table-column label="说明" width="250">
                                    <template slot-scope="{ row }">
                                         <el-input v-model="row.remarks"></el-input>
                                        </template>
                                </el-table-column>
                            </el-table>
            </div>
                            <!-- <ComPagination /> -->
          </div>

          <!-- 附件信息 -->
          <div id="accessoryCon" class="con">
            <div class="tabs-title" id="accessory">附件信息</div>
            <attach-comp
              :relationId="attachId"
              bucketName="turnover"
            />
          </div>

          <!-- 审核历史 -->
          <div id="auditHistoryCon" class="con">
            <div class="tabs-title" id="auditHistory">审核历史</div>
            <div class="e-table">

            <div class="e-table">
                <ComAuditHistoryIndex :billType="1019" :tableData.sync="shenheArr" @getAuditHistory="getauditHistory"   ref="AuditHistoryRef"/>
            </div>
            </div>
          </div>
        </div>
      </el-tabs>
    </div>
    <div id="seat" :style="{ height: seatHeight + 'px' }"></div>
    <div class="buttons">
            <div v-if="Thewas != 'add'">
                <el-button
                type="primary"
                style="background: #2e61d7"
                >打印</el-button
                >
                <exaButtons :auditState="auditState" @exas="exas"></exaButtons>
                <el-button>关闭</el-button>
            </div>
            <div v-if="Thewas == 'add'">
                <!-- <span class="tip"><span style="color: red; margin-right: 0">*</span>为必填项</span> -->
                <el-button
                type="primary"
                class="btn-blue"
                @click="submitCommit"
                size="small"
                >保存并提交</el-button
                >
                <el-button
                    type="primary"
                    class="btn-blue"
                    @click="theSubmit"
                    size="small"
                    >保存</el-button
                >
                <!-- <button @click="chakand">查看</button> -->
                <el-button size="small" @click="handleClose">取消</el-button>
            </div>
        </div>
    <span style="display: none">{{ localPopConfirm }}</span>
  </div>
</template>

<script>
import '@/utils/jquery.scrollTo.min'
import  request  from '@/api/balanceContractApi/getCurrency.js'
import { mapMutations, mapState } from 'vuex'
import { showPromptPop, showSuccessPop, getUuid } from '@/utils/common'
import AttachComp from '@/components/common/attachIndex'
import planRequest from '@/api/turnover/plan.js'
// getRmbRateApi2, getBaseCyInfoApi , getbaseCurrency
import { getBaseCyApi } from '@/api/base/system.js'
import { selectDataClient, openAppClient } from '@/utils/common'

import { getUnit } from '@/api/subcontractApi/currency.js'

import auditRequest from '@/api/materialSettlement/supplierAddpayment.js'

import publicReques from '@/api/materialSettlement/public.js'

import exaButtons from '@/components/common/exaButtons'
// import ComAuditHistoryIndex from '@/pages/revolveMaterialManage/components/auditHistory/auditHistoryIndex'
import ComAuditHistoryIndex from '@/pages/materialsmanagement/components/auditHistory/auditHistoryIndex'
// import historyUpdateTable from '@/components/common/historyUpdateTable'

// import { showLoading, hideLoading } from '@/utils/common'
// import { selectDataClient } from '@/utils/common'

export default {
    components: {
        AttachComp,
        ComAuditHistoryIndex,
        exaButtons
        // historyUpdateTable
    },
    data () {
        return {
            //我的数据:↓
            nullifyParams: {
                // 作废
                billId: this.$route.query.billid,
                billType: '1019',
                nullifyDescription: '',
                nullifyReason: true,
                nullifyCreated: '',
                nullifyCreator: '',
                nullifyCreatorId: ''
            },
            shenheArr: [],
            billId: '',
            state: '',
            formData: {
                billNo: '',
                orgName: '', //单据机构name
                orgId: '',
                contractType: '', //合同类型
                contractName: '', //合同名称
                settlementUnitName: '', //结算单位名称
                settlementUnitId: '', //结算单位ID
                settlementDate: '', //加扣款日期
                plusDeductionAmount: this.jkkje, //加扣款金额
                rmbReturnDepositAmount: 0, //返还保证金金额(人民币)
                currency: '', //币种
                baseCurRate: 0, //本位币汇率
                gx: '', //传财务共享 随便写的 需要改
                baseCurName: '', //本位币name
                baseCurId: '', //本位币id
                state: 0, //状态
                baseCurPlusDeductionAmount: this.jkkjeBwb, //加扣款金额(本位币)
                baseCurReturnDepositAmount: this.bzjjeBwb, //返回保证金金额
                remarks: '', //备注
            },
            typeArr: [
                { name: '草稿', id: 0 },
                { name: '审核中', id: 1 },
                { name: '共享审核中', id: 9 },
                { name: '已审核', id: 2 },
                { name: '已关闭', id: -1 },
                { name: '已作废', id: 5 },
            ],
            viewList: true,
            paginationInfo: {
                total: 1,
                pageSize: 10,
                currentPage: 0
            },
            query: {
                beginPlanDate: '',
                endPlanDate: '',
                keyword: '',
                limit: 0,
                orgId: '',
                page: 1,
                settlementUnitId: '',
                states: []
            }, //搜索
            searchKey: '', //右上角搜索关键字
            tableData: [], //表格
            user: {}, //本地储存用户信息
            jkktableData: [],
            wzmxtable: [],
            bzjtableData: [],
            changeType: 0,
            auditState: {},
            //我的数据:↑

            // auditState: {},
            auditParams: {
                billId: this.$route.query.billid,
                billType: 6087,
                freeNextUnitIndex: 0,
                freeNextUser: '',
                isPass: true,
                isShareInAudit: true,
                opinion: ''
            },
            tabsName: 'baseInfo',
            userName: '',
            clickId: 'baseInfo',
            tabsNameChild: '',
            childTabClass: '',
            form: {
                name: '',
                region: '',
                date1: '',
                date2: '',
                delivery: false,
                type: [],
                resource: '',
                desc: '',
            },

            OrgtableData: [], //申报机构数据
            OrgSonTableData: [], //申报机构子列表
            materialsTableData: [], //物资汇总数据
            auditHistoryList: [], //审核历史
            planSelect: [], //申报机构表格明细选择项
            value: '',
            textarea: '',
            screenWidth: 0,
            screenHeight: 0,
            lastConHeight: 0,
            MouseEnterId: 0,
            clickTabFlag: false, // 如果手动点击时，则不做滚动事件逻辑，只有滚动屏幕时才走滚动事件逻辑
            //基本信息表单数据
            basicFormData: {
                'amount': null,
                'billId': '',
                'billNo': '',
                'founderId': '',
                'founderName': '',
                'gmtCreate': '',
                'gmtModified': '',
                'nullifyCreated': '',
                'nullifyCreator': '',
                'nullifyCreatorId': '',
                'nullifyDescription': '',
                'nullifyReason': '',
                'operator': '',
                'operatorId': '',
                'orgId': '',
                'orgName': '',
                'remarks': '',
                'sourceBillId': '',
                'sourceBillNo': '',
                'sourceType': null,
                'state': '',
                'summaryDate': '',
                'workId': ''
            },
            objFlag: {
                flag5: false,
            },
            orgId: '', //机构id
            orgName: '', //机构名称
            isSkip: false, //是否跳转
            show: true, //申报机构子列表
            dtlIds: '', //
            //验证
            rules: {
                summaryDate: [
                    { required: true, message: '请输入汇总日期', trigger: 'blur' },
                ],
                currencyId: [
                    { required: true, message: '请选择币种', trigger: 'chenge' },
                ],
            },
            materialsNameData: [], //机构汇总表
            createHistoryData: [], //明细修改历史列表
            errorMsg: [],
            isErrorMsg: true, //是否提醒错误信息

        }
    },
    async created () {
        // let data = JSON.parse(localStorage.getItem('vuex'))
        // this.orgId = data.userInfo.orgInfo.orgId
        // this.orgName = data.userInfo.orgInfo.orgName
        // this.userId = localStorage.getItem('userId')
        // this.basicFormData.operator = localStorage.getItem('userName')
        // this.billId = this.$route.query.billid

        // this.initData()
        //先判断是否是新增
        this.was = this.$route.query.was
        this.Thewas = this.$route.query.was
        this.user = JSON.parse(localStorage.getItem('vuex'))
        if(this.was == 'add') {
            //新增页面
            this.user = JSON.parse(localStorage.getItem('vuex'))
            console.log(this.user, 'iii')
            this.$set(this.formData, 'orgName', this.user.userInfo.orgInfo.orgName)
            this.$set(this.formData, 'orgId', this.user.userInfo.orgInfo.orgId)
            console.log(this.user, 'ooo')

            const { list } = await getBaseCyApi({ //获取本位币
                keyWord: '',
                limit: 100,
                page: 1
            })

            // const data4 = await auditRequest.getjsdwlist()
            // console.log('data4', data4)

            // const data4 = await getbaseCurrency('1439990097591140358')
            // console.log(data4, 'data4')
            // const data4 = await getBaseCyInfoApi('1492031931443843074')
            // console.log(data4, 'data4')
            // const dataa = await getRmbRateApi2({

            // })

            const data2 = await auditRequest.getjqkList() //获取加扣款弹窗

            const data3 = await request.getCurrency() //获取币种

            this.danweiArr = await getUnit() //获取单位
            console.log(this.danweiArr, 'data4')

            console.log(list, 'data')
            console.log(data2, 'data2')
            console.log(data3, 'data3')
        }else if(this.was == 'see') {
            this.state = this.$route.query.state
            this.auditState = await publicReques.getCurrentUnitInfo({
                billId: this.$route.query.billid,
                billType: '1019'
            })
            //进入查看页面
            const billid = this.$route.query.billid
            this.billId = this.$route.query.billid

            const data = await auditRequest.getSettlemen({ id: billid })
            this.formData = data
            this.formData.state = this.formData.state - 0

            const jkk = await auditRequest.getjkkmxbyId({ id: billid })
            this.jkktableData = jkk
            for(let i = 0 ; i < this.jkktableData.length; i++) {
                this.jkktableData[i].id = this.jkktableData[i].plusDeductionId
                this.jkktableData[i].name = this.jkktableData[i].plusDeductionName
                this.jkktableData[i].type = this.jkktableData[i].plusDeductionType
            }

            let wzmx = await auditRequest.getwzmxbyId({ id: billid })
            console.log('wzmx', wzmx)
            for(let i = 0 ; i < wzmx.length ; i++) {
                wzmx[i].uuid = getUuid()
                if(wzmx[i].children.length > 0 ) {
                    for(let j = 0 ; j < wzmx[i].children.length ; j++) {
                        wzmx[i].children[j].uuid = getUuid()
                    }
                }
            }
            console.log(this.wzmxtable, 'xxx')
            this.wzmxtable = wzmx

            const bzj = await auditRequest.getbzjbyId({ id: billid })
            this.bzjtableData = bzj

            //   obj.billId = this.billId
            //         //changtype -1 删除  1 新增  2 修改
            //         obj.changeType = 1
            //         obj.dtlId  //这个不知道
            //         obj.previousTotalReturnedAmount = obj.notReturnedAmount - obj.returnAmount || 0
            //         obj.returnDepositId = obj.bondId
            //         obj.returnDepositName = obj.name

            //         //本期末 returnedAmountBqm
            //         obj.currentTotalNotReturnedAmount = obj.notReturnedAmount

            for(let i = 0 ; i < this.bzjtableData.length ; i++) {
                let obj = this.bzjtableData[i]
                //obj.billId = data
                //changtype -1 删除  1 新增  2 修改
                //obj.dtlId  //这个不知道
                obj.notReturnedAmountBqm = obj.notReturnedAmount - obj.returnAmount || 0
                obj.bondId  = obj.returnDepositId
                obj.name = obj.returnDepositName
                obj.notReturnedAmount = obj.currentTotalNotReturnedAmount
            }

            console.log(this.user)
            // await auditRequest.getjcht({ orgId: this.user.userInfo.orgInfo.orgId, })

            console.log(data)
            // hideLoading()
        }
    },
    methods: {
        ...mapMutations(['setPopConfirm', 'setSelectedInfo', 'setHistoryTableData']),

        changnum (type, obj) {
            // 300 100
            // for(let i = 0 ; i < this.wzmxtable.length; i++) {

            // amount apportionmentRatio
            if(type == '金额') {
                console.log(obj.amount, 'money')
                console.log(this.jkkje)
                obj.amount = obj.amount - 0
                obj.apportionmentRatio = obj.amount / this.jkkje * 10
            }else{
                obj.amount = this.jkkje * obj.apportionmentRatio

            }
            console.log(type)
            console.log(obj)
        },
        initData () {
            this.getCurrentUnitInfo()
            this.getTurnoverCentralizedPurchaseSummaryGetAgencyListByBillId()
            this.getBasicData()
            this.getTurnoverCentralizedPurchaseSummaryGetSummarySetting() //回去物资汇总明细
        },
        //获取按钮状态
        getCurrentUnitInfo () {
            auditRequest.getCurrentUnitInfo(this.auditParams).then(res => {
                this.auditState = res
            })
        },
        //根据周材集采汇总id查询申报机构
        getTurnoverCentralizedPurchaseSummaryGetAgencyListByBillId () {
            planRequest.turnoverCentralizedPurchaseSummaryGetAgencyListByBillId(this.billId).then(res=>{
                this.OrgtableData = res
                // this.rollUp(res)
            })
        },
        async getauditHistory () {
            if(this.billId !== '') {
                const data = await publicReques.getauditHistory({
                    'billId': this.billId,
                    'billType': 1019,
                    'freeNextUnitIndex': 0,
                    'freeNextUser': '',
                    'isPass': true,
                    'isShareInAudit': true,
                    'opinion': ''
                })
                console.log(data, 'uuu')
                this.shenheArr = data
            }
        },

        //根据周材集采汇总id查询申报机构
        getTurnoverCentralizedPurchaseSummaryGetSummarySetting () {
            planRequest.turnoverCentralizedPurchaseSummaryGetSummarySetting(this.billId).then(res=>{
                console.log(res, '当前打印')
                // this.OrgtableData = res
                this.notSetData = JSON.parse(JSON.stringify(res)) //没去重之前的数据
                //去重
                let children = []
                res.forEach(item=>{
                    item.children.forEach(a=>{
                        children.push(a)
                    })
                })
                var result = []
                var obj = {}
                for (var i = 0; i < children.length; i++) {
                    if ( children[i].materialId in obj) {
                        // 相同时肯定不push
                        if (obj[children[i].materialId] !== children[i].texture) {
                            // 不相同时，判断是否是 '' 和 null，如果是，则表示重复
                            if (!(!obj[children[i].materialId] && !children[i].texture)) {
                                // 当都不是 '' 和 null 时，才表示不重复，此时才push
                                result.push(children[i])
                            }
                        }
                    } else {
                        obj[children[i].materialId] = children[i].texture
                        result.push(children[i])
                    }
                    // obj[children[i].amount] = 1

                }
                res.forEach(item=>{
                    item.uuid = getUuid()

                    item.materialClassName = item.topClassName
                    item.children = result
                    item.children.forEach(v=>{
                        v.uuid = getUuid()
                        v.parentId = item.uuid
                    })
                })
                console.log(result, 'datadata')
                this.materialsTableData = res
            })
        },

        //向上汇总
        rollUp (res) {
            res.forEach(item=>{ //拿到 数据 汇总计划金额
                this.basicFormData.amount += item.totalAmount
            })
        },
        //点击图标的时候 获取历史记录
        clickIcon (dtlId, column) {
            this.setHistoryTableData([])
            alert(dtlId)
            planRequest
                .turnoverAnnualDemandPlanGetHistoryList(
                    dtlId,
                    column,
                    this.auditParams.billType
                )
                .then(res => {
                    this.historyTableData = res
                    this.setHistoryTableData(res)
                })
                .catch(e => {
                    alert(e.message)
                })
        },
        // 编辑的时候造历史修改数据结构
        createHistory (row, e) {
            if (row.dtlId) {
                this.createHistoryData.push({
                    historyId: '',
                    modifedName: '',
                    modifiedDate: '',
                    modifiedId: '',
                    opinion: '',
                    sourceId: row.dtlId,
                    sourceValue: 0,
                    updateColumn: e, //修改字段
                    updatedValue: row[e] //修改后的值
                })
            }
        },
        /**
         * 下边几个按钮
         */

        //保存按钮
        submit () {
            this.$refs['basicFormData'].validate(valid => {
                if (valid) {
                    const data = JSON.parse(JSON.stringify(this.OrgtableData))

                    // 明细非空验证
                    this.verifyTable()
                    if (this.isErrorMsg) {
                        return
                    }
                    return new Promise((resolve, reject)=>{

                        planRequest.turnoverCentralizedPurchaseSummaryUpdateDtlList(data).then(res=>{
                            resolve(res)
                            showSuccessPop('保存明细成功！', this.initData)
                        }).catch(err=>{
                            reject(err)
                        })
                        if(this.isCollect) { //初次进入页面 点击了申报单位之后的回调s
                            const resource = []
                            data.forEach(item=>{
                                if(item.dtls) {
                                    item.dtls.forEach(v=>{
                                        v.children.forEach(n=>{
                                            n.billId = this.billId
                                        })
                                        resource.push(v)
                                    })
                                }

                            })
                            planRequest.turnoverCentralizedPurchaseSummarySaveSummarySetting(resource).then(res=>{
                                resolve(res)
                                showSuccessPop('保存物资汇总成功！', this.initData)
                            }).catch(err=>{
                                reject(err)
                            })
                        }

                        //修改基础信息
                        planRequest.turnoverCentralizedPurchaseSummaryUpdate(this.basicFormData).then(res => {
                            resolve(res)
                            showSuccessPop('保存基础成功！', this.initData)
                        }).catch(err=>{
                            reject(err)
                        })
                    })

                }
            })
        },
        // 保存并提交
        async submitCommit () {

            if(this.formData.settlementUnitId == '') {
                this.clientPop('err', '请选机材合同')
                return
            }
            if(this.was == 'add') {
                //进行保存前要把计算的属性设置给对象
                this.$set(this.formData, 'plusDeductionAmount', this.jkkje) //加扣款金额
                this.$set(this.formData, 'rmbReturnDepositAmount', this.bzjje) //保证金金额
                this.$set(this.formData, 'baseCurPlusDeductionAmount', this.jkkjeBwb)  //加扣款金额 本位币
                this.$set(this.formData, 'baseCurReturnDepositAmount', this.bzjjeBwb) //保证金金额本位币
                //拿到表1返回的 billid
                this.billId = await auditRequest.onsave(this.formData)
                // // //执行其他保存
                for(let i = 0 ; i < this.jkktableData.length; i++) {
                    this.jkktableData[i].billId = this.billId
                    this.jkktableData[i].plusDeductionId = this.jkktableData[i].id
                    this.jkktableData[i].plusDeductionName = this.jkktableData[i].name
                    this.jkktableData[i].plusDeductionType = this.jkktableData[i].type
                    //  changtype -1 删除  1 新增  2 修改
                    this.jkktableData[i].changeType = 1
                }
                //加扣款进行保存
                await auditRequest.onsavejjk(this.jkktableData)

                // //获取 加扣款明细 列表
                // await auditRequest.getjkkbyId({ id: '1509733905670533121' })
                console.log('表1', this.formData)
                console.log('表2', this.jkktableData)
                console.log('表3', this.wzmxtable)

                //步骤3没写 一会写
                // const list = []
                for(let i = 0 ;i < this.wzmxtable.length ; i++) {
                    // this.wzmxtable[i].topClassId =  this.wzmxtable[i].listId
                    // this.wzmxtable[i].topClassName = this.wzmxtable[i].materialName
                    // this.wzmxtable[i].totalAmount = this.wzmxtable[i].amount
                    // this.wzmxtable[i].totalQuantity = this.wzmxtable[i].quantity
                    if(this.wzmxtable[i].children) {
                        if(this.wzmxtable[i].children.length > 0) {
                            for(let j = 0 ; j < this.wzmxtable[i].children.length ; j++) {
                                this.wzmxtable[i].children[j].billId = this.billId
                                //  this.wzmxtable[i].children[j].contractDtlId = this.wzmxtable[i].listId
                                // this.wzmxtable[i].children[j].materialClassName = this.wzmxtable[i].type
                                // this.wzmxtable[i].children[j].spec = this.wzmxtable[i].specificationModel
                                // this.wzmxtable[i].children[j].texture = this.wzmxtable[i].textureOfMaterial

                                this.wzmxtable[i].children[j].changeType = 1
                            }
                        }
                    }
                }
                await auditRequest.onsavewzhz(this.wzmxtable)

                for(let i = 0 ; i < this.bzjtableData.length ; i++) {
                    let obj = this.bzjtableData[i]
                    obj.billId = this.billId
                    //changtype -1 删除  1 新增  2 修改
                    obj.changeType = 1
                    obj.dtlId  //这个不知道
                    obj.previousTotalReturnedAmount = obj.notReturnedAmount - obj.returnAmount || 0
                    obj.returnDepositId = obj.bondId
                    obj.returnDepositName = obj.name

                    //本期末 returnedAmountBqm
                    obj.currentTotalNotReturnedAmount = obj.notReturnedAmount
                }
                await auditRequest.onsavebzj(this.bzjtableData)
                console.log('表4', this.bzjtableData)
                await publicReques.commitexamine({ billId: this.billId,	billType: '1019' })
                this.clientPop('suc', '提交审核成功', this.handleClose)
            }else{
                //进行保存前要把计算的属性设置给对象
                this.$set(this.formData, 'plusDeductionAmount', this.jkkje) //加扣款金额
                this.$set(this.formData, 'rmbReturnDepositAmount', this.bzjje) //保证金金额
                this.$set(this.formData, 'baseCurPlusDeductionAmount', this.jkkjeBwb)  //加扣款金额 本位币
                this.$set(this.formData, 'baseCurReturnDepositAmount', this.bzjjeBwb) //保证金金额本位币
                //拿到表1返回的 billid
                const data = this.billId
                await auditRequest.update(this.formData)
                // // //执行其他保存
                for(let i = 0 ; i < this.jkktableData.length; i++) {
                    this.jkktableData[i].billId = data
                    this.jkktableData[i].plusDeductionId = this.jkktableData[i].id
                    this.jkktableData[i].plusDeductionName = this.jkktableData[i].name
                    this.jkktableData[i].plusDeductionType = this.jkktableData[i].type
                    //  changtype -1 删除  1 新增  2 修改
                    if(this.jkktableData[i].changeType != -1) {
                        this.jkktableData[i].changeType = 2
                    }
                }
                //加扣款进行保存
                await auditRequest.onsavejjk(this.jkktableData)

                // //获取 加扣款明细 列表
                // await auditRequest.getjkkbyId({ id: '1509733905670533121' })
                console.log('表1', this.formData)
                console.log('表2', this.jkktableData)
                console.log('表3', this.wzmxtable)

                //步骤3没写 一会写
                for(let i = 0 ;i < this.wzmxtable.length ; i++) {
                    if(this.wzmxtable[i].children) {
                        if(this.wzmxtable[i].children.length > 0) {
                            for(let j = 0 ; j < this.wzmxtable[i].children.length ; j++) {
                                this.wzmxtable[i].children[j].changeType = 2
                            }
                        }
                    }
                }
                await auditRequest.onsavebzj(this.wzmxtable)

                for(let i = 0 ; i < this.bzjtableData.length ; i++) {
                    let obj = this.bzjtableData[i]
                    obj.billId = data
                    //changtype -1 删除  1 新增  2 修改
                    if(obj.changeType != -1) {
                        obj.changeType = 2
                    }
                    obj.dtlId  //这个不知道
                    obj.notReturnedAmountBqm = obj.notReturnedAmount - obj.returnAmount || 0
                    obj.returnDepositId = obj.bondId
                    obj.returnDepositName = obj.name
                    obj.returnedAmountBqm = obj.notReturnedAmount
                }
                // await auditRequest.onsavebzj(this.bzjtableData)
                console.log('表4', this.bzjtableData)
            }
            await publicReques.commitexamine({ billId: this.billId,	billType: '1019' })
            this.clientPop('suc', '提交审核成功', this.handleClose)
            // this.$router.replace('/supplierAddpaymentlist')
            // const data = JSON.parse(JSON.stringify(this.OrgtableData))
            // if(!data.length) {
            //     this.clientPop('err', '请选择申报机构!')
            //     return
            // }
            // this.verifyTable()
            // if (this.isErrorMsg) {
            //     return
            // }
            // let promise1 = planRequest.turnoverCentralizedPurchaseSummaryUpdate(
            //     this.basicFormData
            // )
            // const promise2 =  planRequest.turnoverCentralizedPurchaseSummaryUpdateDtlList(data).then()
            // Promise.all([promise1, promise2]).then(() => {
            //     auditRequest.commit(this.auditParams).then(()=>{

            //         this.clientPop('suc', '保存并提交成功', this.handleClose)
            //     })
            // })
        },
        //计划明细非空验证
        verifyTable () {

            this.errorMsg = []
            if(this.OrgtableData.length > 0) {
                this.OrgtableData.forEach((n, index)=>{
                    if(n.dtls) {
                        n.dtls.forEach(v=>{
                            v.children.forEach(item=>{
                                if(item.changeType !== -1) {
                                    if (item.approvalQuantity == '' || item.approvalQuantity == null) {
                                        let str = `请填写第 ${index + 1} 行的核准数量`
                                        this.errorMsg.push(str)
                                    }
                                    if (item.approvalPrice == '' || item.approvalPrice == null) {
                                        let str = `请填写第 ${index + 1} 行的核准单价`
                                        this.errorMsg.push(str)
                                    }

                                }
                            })
                        })
                    }

                })
            }

            if(this.errorMsg.length > 0) {
                this.isErrorMsg = true

            }else{
                this.isErrorMsg = false

            }

        },
        async nullify () {
            console.log('撤回')
            await publicReques.goBack({ billId: this.billId, billType: '1019' })
            this.clientPop('suc', '撤回成功')
            this.$router.replace('/supplierAddpaymentlist')
        },
        async deljkk () {
            await await auditRequest.deljkkbyid({ id: this.billId })
            this.clientPop('suc', '删除成功')
            this.$router.replace('/supplierAddpaymentlist')
        },
        shenhe () {
            console.log('审核')
            openAppClient('/exaDialog', '填写审核意见',  ()=> {
                const auditParams = JSON.parse(localStorage.vuex).auditParams
                // 将审核意见赋值给参数传给后端
                publicReques.goaudit({
                    billId: this.billId,
                    billType: '1019',
                    isPass: auditParams.isPass,
                    isShareInAudit: false,
                    opinion: auditParams.opinion

                }).then(() => {
                    this.clientPop('suc', '审核成功')
                    this.$router.replace('/supplierAddpaymentlist')
                }).catch(()=>{
                    this.clientPop('suc', '审核失败')
                })

            })
            //  openAppClient('/exaDialog', '填写审核意见', () => {
            //                 // 审核拿到审核弹窗的意见
            //                 const auditParams = JSON.parse(localStorage.vuex).auditParams
            //                 // 将审核意见赋值给参数传给后端
            //                 publicReques.goaudit({
            //                     billId: this.$route.query.billid,
            //                     billType: '1019',
            //                     freeNextUnitIndex: 0,
            //                     freeNextUser: '',
            //                     isPass: auditParams.isPass,
            //                     isShareInAudit: true,
            //                     opinion: auditParams.opinion
            //                 }).then(() => {
            //                     this.clientPop('suc', '审核成功')
            //                 })
            //             })
            //         })

        },
        //把子列表的数据合并到this.OrgtableData的children
        DoMaterialsTableData () {
            this.OrgtableData.forEach(item=>{
                item.changeType = 1
                item.billId = this.billId

            })
        },

        //点击选择 选择申报单位 获取申报机构
        selectUnit () {
            planRequest.turnoverCentralizedPurchaseSummaryGetAgencyListByOrgId(['1505122036192309249'])
                .then(res => {
                    this.OrgtableData = res
                    this.DoMaterialsTableData() //给数据造billid 和 chengetype
                    this.isCollect = true
                })
        },
        //点击申报单位列表点击编号显示对应子列表
        tableDbShow (row, column) {
            row.dtls = []
            if(column.label === '年度需用计划编号') {
                if(row.changeType == 1) {
                    planRequest.turnoverCentralizedPurchaseSummaryGetAllMaterial(row.annualDemandPlanBillId).then(res=>{
                        this.OrgSonTableData = res
                        this.OrgSonTableData.forEach(item=>{
                            item.changeType = 1
                            item.uuid =  getUuid()
                            item.materialClassName = item.topClassName

                            item.children.forEach(v=>{
                                v.changeType = 1
                                v.parentId = item.uuid
                                v.uuid =  getUuid()
                            })
                            row.dtls.push(item)
                        })
                    })
                }else {
                    planRequest.turnoverCentralizedPurchaseSummaryGetMaterial(row.dtlId).then(res=>{
                        this.OrgSonTableData = res
                        this.OrgSonTableData.forEach(item=>{
                            item.uuid =  getUuid()
                            item.materialClassName = item.topClassName
                            row.dtls.push(item)
                            item.children.forEach(v=>{
                                v.changeType = 2
                                v.parentId = item.uuid
                                v.uuid =  getUuid()
                            })
                        })
                    })
                }

            }

        },
        async exas (arg) {
            if (arg === 'submit') {
                console.log('1') // 保存所有数据
                await this.theSubmit()
            } else if (arg === 'submitCommit') {
                console.log('2') // 保存并提交
                await this.submitCommit()
            } else if (arg === 'audit') {
                console.log('3') // 审核
                await this.shenhe()
            } else if (arg === 'undoAudit') {
                await this.nullify() // 撤销审核
            } else if (arg === 'nullify') {
                console.log('5') // 作废(
                await this.zuofei()
            } else if (arg === 'deleteData') {
                console.log('6') // 删除
                await this.deljkk()
            }
        },
        zuofei () {
            this.setAuditParams(this.nullifyParams)
            // 客户端弹窗弹出本地页面
            openAppClient('/nullifyDialog', '单据作废原因', () => {
                const auditParams = JSON.parse(localStorage.vuex).auditParams
                // this.setSelectedInfo(auditParams)
                // // 客户端弹窗预览结果
                // // 参数依次为: 打开页面地址、标题、回调函数
                // openAppClient('/showSelectedData', '选择结果', function () {
                //     // alert('关闭后回调')
                // })
                // showLoading()
                publicReques
                    .zuofei(auditParams)
                    .then(() => {
                        this.clientPop('suc', '作废成功', this.handleClose)
                    })
                    // .finally(() => {
                    //     hideLoading()
                    // })
            })
        },
        // 点击子表的选择明细
        selectDetails () {
            console.log('选择明细')
        },
        //点击集中采购单位 选择单位

        clickPurchasingUnit (row) {
            selectDataClient()
            // 弹窗选择数据
            selectDataClient({
                SelectServiceToken: '/hr/org/getChildrenOrg', // 客户端对应方法名
                IsSingleMode: true, // 是否单选 true 单选 false 多选
                SelectedIDs: [], // 已选中id
                Title: '选择全集团组织机构数据', // 标题
                InitParamsStr: JSON.stringify({ orgId: this.basicFormData.orgId }), //参数

            }).then(val => {
                const orgData = val[0] //获取客户端返回的数据
                row.purchasingUnitId = orgData.orgId
                row.purchasingUnitName = orgData.orgName
                row.changeType === 1 ? this.count_(row, 1) : this.count_(row, 2) //判断当前的状态是新增还是修改
                // 保存用户选择返回数据到store
                this.setSelectedInfo(val)
                // 客户端弹窗预览结果
                // 参数依次为: 打开页面地址、标题、回调函数
                // openAppClient('/showSelectedData', '选择结果', function () {
                //     alert('关闭后回调')

                // })
            })
        },
        //点击物资汇总的物资名称，汇总物资下的所有机构
        showA (row) {
            console.log(row, 'row')
            console.log(this.notSetData, 'this.notSetData')
            this.materialsNameData = []
            this.notSetData.forEach(item=>{
                item.children.forEach(b=>{
                    if( row.materialId === b.materialId) {
                        // const obj = {
                        //     orgName: item.orgName,
                        //     materialName: b.materialName,
                        //     spec: b.spec,
                        //     unit: b.unit,
                        //     texture: b.texture,
                        //     planQuantity: b.planQuantity,
                        //     marketPrice: '',
                        //     amount: b.amount
                        // }
                        // this.materialsNameData = []
                        this.materialsNameData.push(b)
                    }
                })
            })

        },
        //申报机构汇总-删除 申报机构汇总表格明细
        deleteMaterials () {
            if (this.planSelect.length > 0) {
                this.OrgtableData.forEach(v=>{
                    this.planSelect.forEach(item=>{
                        if(item.dtlId && item.dtlId === v.dtlId) {
                            v.changeType = -1
                        }
                    })

                })
            }
            if (this.planSelect.length > 0) {
                this.planSelect.forEach(item => {
                    if (item.dtlId) {
                        const newArr = []
                        newArr.push(item)
                        newArr.forEach(item => {
                            this.$set(item, 'changeType', -1)
                        })

                        // this.$refs.multipleTable.clearSelection()
                    } else {
                        const localArr = []
                        localArr.push(item)
                        for (
                            let i = this.OrgtableData.length;
                            i > 0;
                            i--
                        ) {
                            for (let j = 0; j < localArr.length; j++) {
                                if (
                                    this.OrgtableData[i - 1] ===
                                    localArr[j]
                                ) {
                                    this.OrgtableData.splice(i - 1, 1)
                                }
                            }
                        }
                        // this.$refs.multipleTable.clearSelection()
                    }
                })
            }
            console.log(this.OrgtableData)

        },

        //监听明细 机构汇总表格 数据input事件 判断用户是否修改  ，计算金额
        countInput (row) {
            row.changeType === 1 ? this.count_(row, 1) : this.count_(row, 2)
            console.log(this.materialsTableData, '物资汇总')
        },
        // 汇总逻辑
        count_ (row, num) {
            row.changeType = num
            this.basicFormData.amount = null

            row.approvalAmount =  row.approvalQuantity * row.approvalPrice
            this.OrgtableData.forEach(item =>{
                console.log(item, '逻辑汇总')
                item.changeType = num
                this.basicFormData.amount += item.totalAmount = row.approvalAmount  //把汇总的金额给父级 方便汇总计算
                if(item.children) {
                    item.children.forEach(i=>{
                        i.changeType = num
                    })
                }
            })
        },
        //申报机构汇总-明细子列表删除按钮
        deleteEle (row) {

            row.changeType = -1
            this.OrgtableData.forEach(item =>{
                item.changeType = 2
                if(item.dtls) {
                    item.dtls.forEach(v=>{
                        if(v.children) {
                            const data =  v.children.find(i=>{
                                return i.dtlId === row.dtlId
                            })
                            data.changeType = -1

                        }
                    })
                }
            })

        },
        //获取集采汇总id获取基本信息
        getBasicData () {
            planRequest.turnoverCentralizedPurchaseSummaryFindById(this.billId)
                .then(res => {
                    this.basicFormData = res
                })
        },
        //删除提示框
        ctDelete () {
            showPromptPop('确定要删除吗？删除的数据可以在【回收站】还原或彻底删除。')
        },
        //根据集采汇总id删除单据
        delData () {
            planRequest.turnoverCentralizedPurchaseSummaryDelete(this.billId)
                .then(res => {
                    if (res.code == 200) {
                        showSuccessPop('删除成功！')
                        this.isSkip = true
                    }
                    this.$router.push('./revolveCollectList')
                })
        },
        handleFullScreen () {
            this.fullscreen = !this.fullscreen
        },
        //查询附件信息
        getAttach () {
            this.objFlag.flag5 = true
        },
        //申报机构删除逻辑
        tableRowClassName ({ row }) {
            if (row.changeType === -1) {
                return 'warning-row'
            }
            return ''
        },
        //获取用户在 汇总明细-申报机构汇总 表格的已选择项
        planTableSelect (selection) {
            this.planSelect = selection
        },
        //取消
        handleClose () {
            // this.dialogVisible = false
            this.$router.replace('/supplierAddpaymentlist')
        },
        onChangeTab (e) {
            console.log('clickTabFlag: ', this.clickTabFlag)
            $.scrollTo(`#${e.name}`, 500)
            this.clickId = e.name //记录每次点击的id
            // 如果手动点击时，则不做滚动事件逻辑，只有滚动屏幕时才走滚动事件逻辑
            this.clickTabFlag = true
            // 动画结束后，恢复状态
            setTimeout(() => {
                this.clickTabFlag = false
            }, 600)
        },
        // 获取最后一个内容区域的高度，计算底部空白
        getLastConHeight () {
            let si = setInterval(() => {
                // 因为dom异步加载，通过轮询找到渲染后的dom，获取高度
                if (document.getElementById('evaluateCon')) {
                    const lastConHeight =
            document.getElementById('evaluateCon').offsetHeight
                    console.log('lastConHeight: ', lastConHeight)
                    this.lastConHeight = lastConHeight
                    console.log('this.lastConHeight', this.lastConHeight)
                    clearInterval(si)
                    si = null
                }
            }, 100)
        },
        cellClsNm ({ column }) {
            if (column.label === '') {
                return 'fixed-left'
            }
        },

        //本人方法 ↓
        async xzbzj () {
            console.log('返还保证金弹框，选择合同物资明细')
            if(this.formData.settlementUnitId == '') {
                this.clientPop('err', '请选机材合同')
                return
            }
            // const data = await auditRequest.getbzj({ contractId: this.formData.contractBillId, contractType: this.formData.contractType })
            console.log(this.user.userInfo.orgInfo.orgId)
            // alert(this.formData.contractBillId)
            // alert(this.formData.contractType)
            selectDataClient({
                SelectServiceToken: '/materialsettle/purchaseSettlement/listUnreturnAmountForSelect', // 客户端对应方法名
                IsSingleMode: false, // 是否单选 true 单选 false 多选
                SelectedIDs: [], // 已选中id(注意：是上一次已选中的id，不是要传的参数，如果第一次选，则传[])
                // contractId: this.formData.contractBillId, contractType: this.formData.contractType
                InitParamsStr: JSON.stringify(),    // 接口参数(name为模拟参数)
                Title: '选择保证金' // 标题
            }).then(val => {
                // 保存用户选择返回数据到store
                if(val.length > 0) {
                    let data = val
                    for(let i = 0 ; i < data.length ; i++) {
                        data[i].returnAmount = 0
                        this.bzjtableData.push(data[i])
                    }
                }

            })
            // console.log(data, 'data')
            // for(let i = 0 ; i < data.length ; i++) {
            //     data[i].returnAmount = 0
            // }
            // console.log(data, 'data')
            // this.bzjtableData = data
        },
        //选择机材合同弹窗
        async truejcht () {
            //弹窗用到获取数据的方法
            // const data = await auditRequest.getjcht({ orgId: this.user.userInfo.orgInfo.orgId })
            // //默认选择为第一个 测试
            // // ['物资采购', '周材租凭', '加工', '设备采购', '设备租凭', '服务采购'][data[0].contractType]
            // this.formData.contractType = data[0].contractType
            // this.formData.contractName = data[0].contractName
            // this.formData.contractBillId = data[0].contractId
            // this.formData.settlementUnitName = data[0].secondPartyName
            // this.formData.settlementUnitId = data[0].secondPartyId
            // this.formData.baseCurId =  data[0].baseCurId
            // this.formData.baseCurName =  data[0].baseCurName
            // this.formData.currency =  data[0].currencyName
            // this.formData.currencyId =  data[0].currencyId
            // this.formData.baseCurRate =  data[0].baseCurRate

            // // alert(this.user.userInfo.orgInfo.orgId)
            // // console.log(this.user.userInfo.orgInfo.orgId)
            // alert(this.user.userInfo.orgInfo.orgId)
            console.log(this.user.userInfo.orgInfo.orgId)

            const data = await auditRequest.bzjdemo({ keyword: '', limit: 10, orgId: this.user.userInfo.orgInfo.orgId, page: 1, sourceBillId: '' })
            console.log('我非常需要你 !!!!!', data)

            selectDataClient({
                SelectServiceToken: '/subcontract/thirdParty/getSupplierSettlement', // 客户端对应方法名
                IsSingleMode: true, // 是否单选 true 单选 false 多选
                SelectedIDs: [], // 已选中id(注意：是上一次已选中的id，不是要传的参数，如果第一次选，则传[])
                InitParamsStr: JSON.stringify({ orgId: this.user.userInfo.orgInfo.orgId  }),    // 接口参数(name为模拟参数)
                Title: '选择合同' // 标题
            }).then(val => {
                this.setSelectedInfo(val)
                // 客户端弹窗预览结果
                // 参数依次为: 打开页面地址、标题、回调函数
                openAppClient('/showSelectedData', '选择结果', function () {
                    // alert('关闭后回调')
                })
                if(val.length > 0) {

                    this.formData.contractType = val[0].contractType
                    this.formData.contractName = val[0].contractName
                    this.formData.contractBillId = val[0].contractId
                    this.formData.settlementUnitName = val[0].secondPartyName
                    this.formData.settlementUnitId = val[0].secondPartyId
                    this.formData.baseCurId =  val[0].baseCurId
                    this.formData.baseCurName =  val[0].baseCurName
                    this.formData.currency = val[0].currencyName
                    this.formData.currencyId =  val[0].currencyId
                    this.formData.baseCurRate =  val[0].baseCurRate

                }
            })
        },
        //选择物资明细
        async addhtqd () {
            console.log('呜呼')
            if(this.formData.settlementUnitId == '') {
                this.clientPop('err', '请选机材合同')
                return
            }
            let ids = []
            selectDataClient({
                SelectServiceToken: '/material/categoryLibrary/queryListByParentClassId2',
                IsSingleMode: false, // 是否单选 true 单选 false 多选
                SelectedIDs: ids, // 已选中id
                InitParamsStr: JSON.stringify({ 'materialType': 0 }),
                Title: '物料选择'
            })
                .then(val => {
                    this.setSelectedInfo(val)
                    const mapObj = {}
                    let arr = []
                    val.forEach(e => {
                        const children = []
                        e.materialClassNameArr = e.classNamePath.split('/')
                        e.materialClassIdArr = e.classIdPath.split('/')
                        // TODO: 统计小计
                        let obj
                        const topClassId = e.materialClassIdArr.splice(0, 1).toString()
                        const topClassName = e.materialClassNameArr.splice(0, 1).toString()
                        if (!mapObj[topClassId]) {
                            obj = {
                                topClassId,
                                topClassName,
                                customId: topClassId,
                                materialClassId: topClassId,
                                materialClassName: topClassName,
                                uuid: getUuid(),
                                totalAmount: '',
                                totalQuantity: '',
                            }
                            //这里需要改成push多个对象   还没改
                            arr.push(obj)

                            mapObj[topClassId] = obj
                        } else {
                            obj = mapObj[topClassId]
                        }

                        // 物资名称
                        children.push({
                            'uuid': getUuid(),
                            'customId': getUuid(),
                            'billId': this.billid,
                            'billNo': this.basicFormData.billNo,
                            'budgetAmount': 0, //预算金额(元)
                            'budgetAmountChanged': 0, //变更后预算金额(元)
                            'budgetPrice': 0, //预算单价(元)
                            'budgetPriceChanged': 0, //变更后预算单价(元)
                            'changeType': 1,
                            'designQuantity': 0, //设计数量
                            'designQuantityChanged': 0, //变更后设计数量
                            'dtlId': '', //物资总计划明细id
                            'marketAmount': 0, //市场金额(元)
                            'marketAmountChanged': 0, //变更后市场金额(元)
                            'marketPrice': 0, //市场单价(元)
                            'marketPriceChanged': 0, //变更后市场单价(元)
                            'masterPlanDtlId': '', //物资总计划明细id
                            'materialClassId': e.materialClassIdArr.join('/'), //物资类别id(
                            'materialClassName': e.materialClassNameArr.join('/'), //物资类别名称
                            'materialId': e.billId, //物资id
                            'materialName': e.materialName, //物资名称
                            'planQuantity': 0, //计划数量
                            'planQuantityChanged': 0, //变更后计划数量
                            'projectPlanDtlId': '', //工程计划明细id
                            'purchaseType': null, //采购方式
                            'purchaseTypeChanged': null, //变更后采购方式
                            'purchasingUnitId': '', //采购单位id
                            'purchasingUnitIdChanged': '', //变更后采购单位id
                            'purchasingUnitName': '', //采购单位名称
                            'purchasingUnitNameChanged': '', //变更后采购单位名称
                            'spec': e.spec, //规格型号
                            'texture': e.texture, //材质
                            'unit': e.unit, //计量单位
                        })
                        obj.children = !obj.children
                            ? children
                            : obj.children.concat(children)
                        // 统计小计
                        const count = obj.children.reduce(
                            (prev, c) => (prev += c.designQuantity || 0),
                            0
                        )
                        obj.materialName = `小计： ${count}`
                        obj.children = this.uniqueArray(obj.children, 'customId')
                    })
                    this.wzmxtable = arr
                    this.collectCount()
                    this.countBudgetAmountChanged()

                })
            // const data = await auditRequest.getwzmx({ contractId: this.formData.contractBillId + '', contractType: this.formData.contractType + '' })
            // console.log(data)
            // data[0].children = []
            // data[0].children.push({
            //     amount: 888,
            //     listId: '3',
            //     materialName: 'demo',
            //     parentId: '1',
            //     quantity: 5,
            //     specificationModel: '规格',
            //     textureOfMaterial: '材质',
            //     type: 'tyupe',
            //     unit: 'unit'
            // })
            // this.wzmxtable = data

            // selectDataClient({
            //     SelectServiceToken: '/subcontract/thirdParty/getSupplierList', // 客户端对应方法名
            //     IsSingleMode: false, // 是否单选 true 单选 false 多选
            //     SelectedIDs: [], // 已选中id(注意：是上一次已选中的id，不是要传的参数，如果第一次选，则传[])
            //     InitParamsStr: JSON.stringify({ contractId: this.formData.contractBillId + '', contractType: this.formData.contractType + '' }),    // 接口参数(name为模拟参数)
            //     Title: '合同清单' // 标题
            // }).then(async val => {
            //     // 保存用户选择返回数据到store
            //     if(val.length > 0 ) {
            //         //后端接口没写好 先模拟收到的数据
            //         let res = [
            //             //                 {
            //             //     "listId": "2",
            //             //     "type": "物资类别",
            //             //     "materialName": "物资名称",
            //             //     "specificationModel": "规格",
            //             //     "textureOfMaterial": "材质",
            //             //     "unit": "单位",
            //             //     "quantity": 6,
            //             //     "amount": 302,
            //             //     "parentId": "父id"
            //             // }
            //             {
            //                 billId: '123456678', //单据id
            //                 contractId: '11111', //合同Id
            //                 listId: '2',
            //                 contractName: '合同名称1', //合同名称
            //                 contractNumber: '合同编号123', //合同编号
            //                 materialName: '空气滤芯', //物资名称
            //                 materialTypeId: '11111/222222/33333', //物资类别id
            //                 materialTypeName: '主要材料/建筑钢材/一级钢材', //物资类别名称
            //                 parentId: '0', //父id
            //                 quantity: 1254, //合同数量
            //                 specificationModel: '规格1', //规格
            //                 supplierName: '供应商1', //供应商名称
            //                 surplusQuantity: 55, //剩余未收料数量
            //                 textureOfMaterial: '材质1', //材质
            //                 unit: '单位1', //单位
            //             }
            //         ]
            //         const mapObj = {}
            //         let arr = []
            //         res.forEach(e => {
            //             const children = []
            //             this.basicFormData.sourceNumber = e.contractNumber
            //             this.basicFormData.supplierName = e.supplierName
            //             e.materialClassNameArr = e.materialTypeName.split('/')
            //             e.materialClassIdArr = e.materialTypeId.split('/')
            //             // TODO: 统计小计
            //             let obj
            //             const topClassId = e.materialClassIdArr.splice(0, 1).toString()
            //             const topClassName = e.materialClassNameArr.splice(0, 1).toString()
            //             if (!mapObj[topClassId]) {
            //                 obj = {
            //                     topClassId,
            //                     topClassName,
            //                     customId: topClassId,
            //                     materialClassId: topClassId,
            //                     materialClassName: topClassName,
            //                     uuid: getUuid(),
            //                     totalAmount: null,
            //                     totalQuantity: null,
            //                 }
            //                 //这里需要改成push多个对象   还没改
            //                 arr.push(obj)

            //                 mapObj[topClassId] = obj
            //             } else {
            //                 obj = mapObj[topClassId]
            //             }

            //             // 物资名称
            //             //   type 物资类别
            //             //   materialName 物资名称
            //             //   specificationModel 规格
            //             //   textureOfMaterial 材质
            //             //   unit 单位
            //             //   amount 金额
            //             //   apportionmentRatio 分摊比例
            //             console.log(e, 'ee')
            //             children.push({
            //                 uuid: getUuid(),
            //                 billId: this.billId,
            //                 billNo: this.basicFormData.billNo,
            //                 customId: getUuid(),
            //                 acceptedQuantity: null, //已验收数量
            //                 changeType: 1,
            //                 dtlId: '', //加工收料明细id
            //                 materialClassId: e.materialClassIdArr.join('/'), //物资类别id(
            //                 materialClassName: e.materialClassNameArr.join('/'), //物资类别名称
            //                 materialId: e.listId, //物资id
            //                 materialName: e.materialName, //物资名称
            //                 price: 0, //单价
            //                 quantity: e.surplusQuantity, //数量
            //                 sourceDtlId: '', //源单明细id
            //                 spec: e.specificationModel, //规格型号
            //                 texture: e.textureOfMaterial, //材质
            //                 unit: e.unit, //计量单位
            //                 warehouseId: '', //仓库id
            //                 warehouseName: '', //仓库名称
            //             })
            //             obj.children = !obj.children
            //                 ? children
            //                 : obj.children.concat(children)
            //             // 统计小计
            //             const count = obj.children.reduce(
            //                 (prev, c) => (prev += c.amount || 0),
            //                 0
            //             )
            //             obj.materialName = `小计： ${count}`
            //             obj.children = this.uniqueArray(obj.children, 'customId')
            //         })
            //         this.wzmxtable = arr
            //     }
            //     // if(val.length > 0) {
            //     //     let data = await auditRequest.getwzmx({ contractId: this.formData.contractBillId, contractType: this.formData.contractType }) //获取列表
            //     //     val.push({
            //     //         amount: 888,
            //     //         listId: '3',
            //     //         materialName: 'demo',
            //     //         parentId: '1',
            //     //         quantity: 5,
            //     //         specificationModel: '规格',
            //     //         textureOfMaterial: '材质',
            //     //         type: 'tyupe',
            //     //         unit: 'unit'
            //     //     })
            //     //     let arr = []
            //     //     //进行筛选
            //     //     //进行筛选
            //     //     for(let i = 0 ; i < val.length; i++) {
            //     //         if(val[i].parentId == '0') {
            //     //             val[i].children = []
            //     //             arr.push(val[i])
            //     //         }else{
            //     //             //说明不是顶级 是 子级
            //     //             //寻找arr里面有没有父级 没有就添加
            //     //             let ishaveFather = false
            //     //             let Iindex = 0
            //     //             for(let j = 0 ;j < arr.length ; j++) {
            //     //                 if(val[i].parentId == arr[j].listId) {
            //     //                     ishaveFather = true
            //     //                     Iindex = j
            //     //                     break
            //     //                 }
            //     //             }
            //     //             if(ishaveFather) {
            //     //                 arr[Iindex].children.push(val[i])
            //     //             }else{
            //     //                 for(let j = 0 ; j < data.length ; j++) {
            //     //                     if(val[i].parentId == data[j].listId) {
            //     //                         val[i].children = []
            //     //                         arr.push(val[i])
            //     //                     }
            //     //                 }
            //     //             }
            //     //         }
            //     //     }
            //     //     this.wzmxtable = arr
            //     // }
            // })
        },
        //明细数据汇总方法
        uniqueArray (arr, key) {
            const map = new Map()
            return arr.filter(item => {
                const val = item[key] + '' || getUuid()
                return !map.has(val) && map.set(val, 1)
            })
        },
        //点击新增加扣款
        async addjkk () {
            // const data = await auditRequest.getjqkList() //获取加扣款弹窗
            // this.jkktableData.push(...data)
            if(this.formData.settlementUnitId == '') {
                this.clientPop('err', '请选机材合同')
                return
            }

            selectDataClient({

                SelectServiceToken: '/materialsettle/common/getPlusDeductionList', // 客户端对应方法名
                IsSingleMode: false, // 是否单选 true 单选 false 多选
                SelectedIDs: [], // 已选中id(注意：是上一次已选中的id，不是要传的参数，如果第一次选，则传[])
                InitParamsStr: '',    // 接口参数(name为模拟参数)
                Title: '选择扣款明细' // 标题
            }).then(val => {
                this.jkktableData.push(...val)
                // 保存用户选择返回数据到store
                // this.setSelectedInfo(val)
                // // 客户端弹窗预览结果
                // // 参数依次为: 打开页面地址、标题、回调函数
                // openAppClient('/showSelectedData', '选择结果', function () {
                //     alert('关闭后回调')
                // })
            })
            // console.log(data)
        },
        //点击保存
        async theSubmit () {
            //物资汇总的接口
            // getSettingListById
            if(this.formData.settlementUnitId == '') {
                this.clientPop('err', '请选机材合同')
                return
            }
            if(this.was == 'add') {
                //进行保存前要把计算的属性设置给对象
                this.$set(this.formData, 'plusDeductionAmount', this.jkkje) //加扣款金额
                this.$set(this.formData, 'rmbReturnDepositAmount', this.bzjje) //保证金金额
                this.$set(this.formData, 'baseCurPlusDeductionAmount', this.jkkjeBwb)  //加扣款金额 本位币
                this.$set(this.formData, 'baseCurReturnDepositAmount', this.bzjjeBwb) //保证金金额本位币
                //拿到表1返回的 billid
                this.billId = await auditRequest.onsave(this.formData)
                // // //执行其他保存
                for(let i = 0 ; i < this.jkktableData.length; i++) {
                    this.jkktableData[i].billId = this.billId
                    this.jkktableData[i].plusDeductionId = this.jkktableData[i].id
                    this.jkktableData[i].plusDeductionName = this.jkktableData[i].name
                    this.jkktableData[i].plusDeductionType = this.jkktableData[i].type
                    //  changtype -1 删除  1 新增  2 修改
                    this.jkktableData[i].changeType = 1
                }
                //加扣款进行保存
                await auditRequest.onsavejjk(this.jkktableData)

                // //获取 加扣款明细 列表
                // await auditRequest.getjkkbyId({ id: '1509733905670533121' })
                console.log('表1', this.formData)
                console.log('表2', this.jkktableData)
                console.log('表3', this.wzmxtable)

                //步骤3没写 一会写
                // const list = []
                for(let i = 0 ;i < this.wzmxtable.length ; i++) {
                    // this.wzmxtable[i].topClassId =  this.wzmxtable[i].listId
                    // this.wzmxtable[i].topClassName = this.wzmxtable[i].materialName
                    // this.wzmxtable[i].totalAmount = this.wzmxtable[i].amount
                    // this.wzmxtable[i].totalQuantity = this.wzmxtable[i].quantity
                    if(this.wzmxtable[i].children) {
                        if(this.wzmxtable[i].children.length > 0) {
                            for(let j = 0 ; j < this.wzmxtable[i].children.length ; j++) {
                                this.wzmxtable[i].children[j].billId = this.billId
                                //  this.wzmxtable[i].children[j].contractDtlId = this.wzmxtable[i].listId
                                // this.wzmxtable[i].children[j].materialClassName = this.wzmxtable[i].type
                                // this.wzmxtable[i].children[j].spec = this.wzmxtable[i].specificationModel
                                // this.wzmxtable[i].children[j].texture = this.wzmxtable[i].textureOfMaterial

                                this.wzmxtable[i].children[j].changeType = 1
                            }
                        }
                    }
                }
                await auditRequest.onsavewzhz(this.wzmxtable)

                for(let i = 0 ; i < this.bzjtableData.length ; i++) {
                    let obj = this.bzjtableData[i]
                    obj.billId = this.billId
                    //changtype -1 删除  1 新增  2 修改
                    obj.changeType = 1
                    obj.dtlId  //这个不知道
                    obj.previousTotalReturnedAmount = obj.notReturnedAmount - obj.returnAmount || 0
                    obj.returnDepositId = obj.bondId
                    obj.returnDepositName = obj.name

                    //本期末 returnedAmountBqm
                    obj.currentTotalNotReturnedAmount = obj.notReturnedAmount
                }
                await auditRequest.onsavebzj(this.bzjtableData)
                this.clientPop('suc', '保存成功', this.handleClose)
                console.log('表4', this.bzjtableData)
            }else{
                //进行保存前要把计算的属性设置给对象
                this.$set(this.formData, 'plusDeductionAmount', this.jkkje) //加扣款金额
                this.$set(this.formData, 'rmbReturnDepositAmount', this.bzjje) //保证金金额
                this.$set(this.formData, 'baseCurPlusDeductionAmount', this.jkkjeBwb)  //加扣款金额 本位币
                this.$set(this.formData, 'baseCurReturnDepositAmount', this.bzjjeBwb) //保证金金额本位币
                //拿到表1返回的 billid
                const data = this.billId
                await auditRequest.update(this.formData)
                // // //执行其他保存
                for(let i = 0 ; i < this.jkktableData.length; i++) {
                    this.jkktableData[i].billId = data
                    this.jkktableData[i].plusDeductionId = this.jkktableData[i].id
                    this.jkktableData[i].plusDeductionName = this.jkktableData[i].name
                    this.jkktableData[i].plusDeductionType = this.jkktableData[i].type
                    //  changtype -1 删除  1 新增  2 修改
                    if(this.jkktableData[i].changeType != -1) {
                        this.jkktableData[i].changeType = 2
                    }
                }
                //加扣款进行保存
                await auditRequest.onsavejjk(this.jkktableData)

                // //获取 加扣款明细 列表
                // await auditRequest.getjkkbyId({ id: '1509733905670533121' })
                console.log('表1', this.formData)
                console.log('表2', this.jkktableData)
                console.log('表3', this.wzmxtable)

                //步骤3没写 一会写
                for(let i = 0 ;i < this.wzmxtable.length ; i++) {
                    if(this.wzmxtable[i].children) {
                        if(this.wzmxtable[i].children.length > 0) {
                            for(let j = 0 ; j < this.wzmxtable[i].children.length ; j++) {
                                this.wzmxtable[i].children[j].changeType = 2
                            }
                        }
                    }
                }
                await auditRequest.onsavebzj(this.wzmxtable)

                for(let i = 0 ; i < this.bzjtableData.length ; i++) {
                    let obj = this.bzjtableData[i]
                    obj.billId = data
                    //changtype -1 删除  1 新增  2 修改
                    if(obj.changeType != -1) {
                        obj.changeType = 2
                    }
                    obj.dtlId  //这个不知道
                    obj.notReturnedAmountBqm = obj.notReturnedAmount - obj.returnAmount || 0
                    obj.returnDepositId = obj.bondId
                    obj.returnDepositName = obj.name
                    obj.returnedAmountBqm = obj.notReturnedAmount
                }
                await auditRequest.onsavebzj(this.bzjtableData)
                console.log('表4', this.bzjtableData)
            }
            this.$router.replace('/supplierAddpaymentlist')
        }

    },
    computed: {
        // 我的计算属性 ↓
        jkkje () {
            let num = 0
            if(this.jkktableData.length > 0) {
                for(let i = 0 ; i <  this.jkktableData.length ; i++) {
                    if(this.jkktableData[i].amount) {
                        if( this.jkktableData[i].type == 1) {
                            num  += (this.jkktableData[i].amount - 0)
                        }else{
                            num -= (this.jkktableData[i].amount - 0)
                        }
                    }
                }
            }
            return num
        },
        //加扣款金额本位币
        jkkjeBwb () {
            let num = 0
            if(this.formData.baseCurRate) {
                num = this.jkkje * this.formData.baseCurRate
            }
            console.log('num', num)
            return num
        },
        bzjje () {
            let num = 0
            console.log(this.bzjtableData, 'lll')
            if( this.bzjtableData.length > 0) {
                for(let i = 0 ; i <  this.bzjtableData.length ; i++) {
                // if(this.bzjtableData[i].amount) {
                    if(this.bzjtableData[i].returnAmount) {
                        num  += (this.bzjtableData[i].notReturnedAmount - this.bzjtableData[i].returnAmount)
                    }else{
                        num  += (this.bzjtableData[i].notReturnedAmount - 0)
                    }
                // }
                }
            }
            return num
        },
        //保证金额 本位币
        bzjjeBwb () {
            let num = 0
            if(this.formData.baseCurRate) {
                num = (this.bzjje * this.formData.baseCurRate)
            }
            return num
        },
        // 我的计算属性 ↑
        ...mapState({
            options: state => state.contract.ctClassify,
            popConfirm: 'popConfirm',
            popStatus: 'popStatus',
            userInfo: state => state.userInfo,
            currencyForm: state => state.equip.equipData.currencyForm//币种
        }),
        localPopConfirm () {
            if (this.popConfirm) {
                switch (this.popStatus) {
                case 'prompt':
                    this.delData()
                    break
                case 'success':
                    if (this.isSkip) this.handleClose()
                    break
                }
                this.setPopConfirm(false)
            }
            return this.popConfirm
        },
        judgeRoute () {
            if (this.$route.path.includes('Add')) {
                return false
            }
            return true
        },
        // 填补底部空白，以使高度够滚动
        seatHeight () {
            return this.screenHeight - 72 - this.lastConHeight
        },
        attachId () {
            return this.billId
        },
        statusLable () {
            return param => {
                const state = this.$store.state.equip.equipData.state
                const obj = state.find(x => x.value == param)

                if (obj !== undefined) {
                    return obj.label
                }
            }
        },
    },

    mounted () {
    // 获取最后一个内容区域的高度，计算底部空白
        this.getLastConHeight()

        // 保存所有tabName
        const arr = [
            'baseInfo',
            'fhbzj',
            ['planDetail', 'materialDetails', 'technicalParameter'],
            'accessory',
            'auditHistory',
        ]
        let $idsTop = []
        window.addEventListener('scroll', () => {
            // 如果手动点击时，则不做滚动事件逻辑，只有滚动屏幕时才走滚动事件逻辑
            //当点击的tab有子tab时做滚动逻辑
            if (this.clickTabFlag && arr.find(x => x === this.clickId)) {
                this.childTabClass = '' //无子tab时清空tab的类名
                return
            }

            if (!$idsTop[$idsTop.length - 1]) {
                $idsTop = arr.map(item => {
                    let itemTop
                    let arr
                    if (item instanceof Array) {
                        const prevHeight = document.getElementById(item[0]).offsetHeight //因这里一个选项有两个表格，需获取前一个表格的高度进行计算
                        arr = item.map((x, i) => {
                            if (i === 0) {
                                return document.getElementById(x).offsetTop
                            } else {
                                return (
                                    document.getElementById(x).offsetTop +
                  prevHeight +
                  document.getElementById(item[0]).offsetTop
                                )
                            }
                        })
                        return arr
                    } else {
                        itemTop = document.getElementById(item).offsetTop
                        return itemTop
                    }
                })
            }
            const scrollTop =
        document.documentElement.scrollTop || document.body.scrollTop
            // 倒序查找
            let curLocal = 0
            let curLocalChild = 1
            for (let len = $idsTop.length, i = len - 1; i >= 0; i--) {
                if ($idsTop[i] instanceof Array) {
                    let item = $idsTop[i]
                    for (let lenth = item.length, j = lenth - 1; j >= 1; j--) {
                        let itemChild = $idsTop[i][j]
                        if (scrollTop + 1 >= itemChild) {
                            curLocalChild = j
                            break
                        }
                    }
                    if (scrollTop + 1 >= item[0]) {
                        curLocal = i
                        break
                    }
                } else {
                    let item = $idsTop[i]
                    if (scrollTop + 1 >= item) {
                        curLocal = i
                        break
                    }
                }
            }
            // 设置对应tabName
            if (arr[curLocal] instanceof Array) {
                this.tabsName = arr[curLocal][0]
                this.tabsNameChild = arr[curLocal][curLocalChild]
            } else {
                this.tabsName = arr[curLocal]
            }
            //动态改变二级选项卡类名
            arr.forEach((item, index) => {
                if (item instanceof Array) {
                    let tabNavHeight = document.querySelector('.childTab .el-tabs__nav')
                        ? document.querySelector('.childTab .el-tabs__nav').offsetHeight
                        : 0
                    if (scrollTop + 1 >= $idsTop[index + 1] - tabNavHeight) {
                        this.childTabClass = 'childTab2'
                    } else if (scrollTop <= $idsTop[index][1]) {
                        this.childTabClass = ''
                    } else {
                        this.childTabClass = 'childTab1'
                    }
                }
            })
        })

        this.screenWidth = document.documentElement.clientWidth
        this.screenHeight = document.documentElement.clientHeight
        window.addEventListener('resize', () => {
            this.screenWidth = document.documentElement.clientWidth
            this.screenHeight = document.documentElement.clientHeight
            $idsTop = arr.map(item => {
                let itemTop
                let arr
                if (item instanceof Array) {
                    const prevHeight = document.getElementById(item[0]).offsetHeight //因这里一个选项有两个表格，需获取前一个表格的高度进行计算
                    arr = item.map((x, i) => {
                        if (i === 0) {
                            return document.getElementById(x).offsetTop
                        } else {
                            return (
                                document.getElementById(x).offsetTop +
                prevHeight +
                document.getElementById(item[0]).offsetTop
                            )
                        }
                    })
                    return arr
                } else {
                    itemTop = document.getElementById(item).offsetTop
                    return itemTop
                }
            })
        })
    },
}
</script>

<style lang="scss" scoped>
.buttons {
  left: 0;
}
.e-form {
  margin-bottom: 80px;
  padding: 0 20px;
  .tabs-title::before {
    content: "";
    height: 22px;
    width: 8px;
    border-radius: 40px;
    background-color: #2e61d7;
    display: block;
    position: absolute;
    left: 20px;
    margin-right: 20px;
  }
}

.e-table {
  background: #fff;
}
::v-deep.el-table .warning-row {
  display: none;
}
// ::v-deep.el-table__body-wrapper::-webkit-scrollbar{
//      width: 6px !important; // 横向滚动条
//     height: 10px !important// 纵向滚动条
// }

::v-deep .el-table__body-wrapper::-webkit-scrollbar {
  width: 6px; // 横向滚动条
  height: 10px; // 纵向滚动条
}
// 滚动条的滑块
::v-deep .el-table__body-wrapper::-webkit-scrollbar-thumb {
  background-color: #ddd;
  border-radius: 5px;
}

.el-tab-pane {
  margin-left: -10px;
}
.childTab {
  ::v-deep .el-tabs__header {
    position: absolute !important;
  }
  ::v-deep .el-tabs__content {
    padding: 0 0 0 20px !important;
  }
}
.childTab1 {
  ::v-deep .el-tabs__header {
    position: absolute !important;
    .el-tabs__nav-scroll {
      position: relative;
      .el-tabs__nav {
        position: fixed;
        top: 0;
        width: 190px;
      }
    }
  }
}
.childTab2 {
  ::v-deep .el-tabs__header {
    position: absolute !important;
    .el-tabs__nav-scroll {
      position: relative;
      .el-tabs__nav {
        position: absolute;
        bottom: 0;
        width: 100%;
      }
    }
  }
}
</style>